PlaceType = {
    superMarket: {
        sells: [ 'tomatoes', 'bread', 'water' ]
    },
    dentistOffice: {
        services: [ 'orthodontics' ]
    },
    bar: {
        sells: [ 'alcohol', 'beer', 'vodka' ]
    },
    mall: {
        sells: [ 'dishware' ]
    }
};

(function() {
    for (var name in PlaceType) {
        if (PlaceType.hasOwnProperty(name)) {
            var type = PlaceType[name];
            type.name = name;
            if (type.sells) {
                type.sellsHash = type.sells.hash();
            }
            if (type.services) {
                type.servicesHash = type.services.hash();
            }
        }
    }
})();

PlaceTypes = {
    selling: function() {
        var seen = {};
        var types = [];
        $.each(arguments, $.proxy(function(_, items) {
            if (!$.isArray(items)) {
                items = [items];
            }

            $.each(items, $.proxy(function(_, item) {
                var a = this.sellingItem(item, seen);
                $.each(a, function(_, t) {
                    types.push(t);
                });
            }, this));
        }, this));
        return types;
    },

    sellingItem: function(item, seen) {
        var types = [];
        for (var name in PlaceType) {
            if (PlaceType.hasOwnProperty(name)) {
                var type = PlaceType[name];
                if (type.sellsHash && type.sellsHash[item] && !seen[name]) {
                    seen[name] = 1;
                    types.push(type);
                }
            }
        }
        return types;
    }
};
